package com.qf.cloud2204.feign.controller;

import com.qf.cloud2204.common.entity.User;
import com.qf.cloud2204.feign.feignclient.MircoAClient;
import com.qf.cloud2204.feign.feignclient.MircoTokenClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jws.soap.SOAPBinding;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/f")
public class FeignController {
    @Autowired
    MircoAClient mircoAClient;
    @Autowired
    MircoTokenClient mircoTokenClient;
    @GetMapping("/test1")
    public String test1(){
        //调用微服务A的hello接口
        String result = mircoAClient.hello();//好像一个本地方法调用
        return result;
    }
    @GetMapping("/test2")
    public String test2(){
        //调用微服务A的findAll接口
        List<User> users = mircoAClient.findAll();
        System.out.println(users);
        return users.toString();
    }
    @GetMapping ("/test3")
    public User test3(){
        //调用微服务A的updateUser接口
        User luobin = new User(300, "luobin");
        User user = mircoAClient.updateUser(luobin);
        return user;
    }

    @GetMapping("/test4")
    public User test4(){
        // 调用微服务A的 delete 接口
        User user = mircoAClient.deleteUser(100);
        return user;
    }
    @GetMapping("/test5")
    public User test5(){
        // 调用微服务A的 delete 接口
        User user = mircoAClient.findUserByName("zhangsan");
        return user;
    }
    //用feign调用MICROTOKEN服务的genToken接口
    @GetMapping("/test6")
    public Map<String, Object> test6(){
        // 调用微服务micro-token的 gentoken 接口
        HashMap<String, Object> map = mircoTokenClient.genToken("13804105576");
        return map;
    }

    @GetMapping("/test7")
    public Map<String, Object> test7(){
        // 调用微服务micro-token的 verify 接口
        HashMap<String, Object> map = mircoTokenClient.verify("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJudW1iZXIiOiIxMzgwNDEwNTU3NiIsImV4cCI6MTY4NDQxMjA0MH0.Q61M-CJ98vRXxTTr1TYwSuuOpGT_29pzwC3AZ6-s0K8");
        return map;
    }

}
